home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / fido / mmail.000 / mmail / mmail.0.1 / interface / letter.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-27  |  18.4 KB  |  804 lines

  1. /*
  2.  * MultiMAIL offline mail reader
  3.  * 
  4.  
  5.    Written by Kolossvary Tamas (thomas@vma.bme.hu)
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 2, or (at your option)
  10.    any later version.
  11.  
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "interface.h"
  22.  
  23. extern mmail            mm;
  24. extern AreaListWindow        areas;
  25. extern LetterListWindow     letters;
  26. extern LetterWindow         letterwindow;
  27. extern HelpWindow         helpwindow;
  28. extern letter_list         *letterList;
  29. extern Interface         *interface;
  30. extern int getstring(WINDOW *, int, int, char *, int, int, int);  
  31.  
  32. //*************        ListWindow        *****************
  33.  
  34. ListWindow::ListWindow(void)
  35. {
  36.  position=0;
  37.  active=0;
  38. }
  39.  
  40. void ListWindow :: Move(direction dir)
  41. {
  42.  switch(dir)
  43.  {
  44.     case UP:    if(position+active > 0) 
  45.             {
  46.              active--;
  47.              if(active == position-1)
  48.                 position--;
  49.             }
  50.             break;
  51.     case DOWN:    if(active+1 < NumOfItems())
  52.             {
  53.              active++; 
  54.              if(active-position+1 >= list_max_y)
  55.                 position++;
  56.             }
  57.             break;
  58.     case PGUP:    position-=list_max_y-1;
  59.             active-=list_max_y-1;
  60.             if(active < 0) active = 0;
  61.             if (position < 0) position = 0;
  62.             break;
  63.     case PGDN:    position+=list_max_y-1;
  64.             active+=list_max_y-1;
  65.             if(active >= NumOfItems())
  66.                 active=NumOfItems()-1;
  67.             if(position > NumOfItems()-list_max_y)
  68.                 {
  69.                  position=NumOfItems()-list_max_y+1;
  70.                  if (position < 0) position = 0;
  71.                 }
  72.             break;
  73.     case HOME:    active=0; 
  74.             position=0; 
  75.             break;
  76.     case END:    active=NumOfItems()-1;
  77.             position=NumOfItems()-list_max_y+1;
  78.             if(position < 0) position = 0;
  79.             break;
  80.  }
  81. }
  82.  
  83. void ListWindow :: ReDraw(void)
  84. {
  85.  touchwin(list);
  86.  wnoutrefresh(list);
  87. }
  88.  
  89. //****************       LETTTERLIST          ****************
  90.  
  91. LetterListWindow :: LetterListWindow(void)
  92. {
  93.  position=0;
  94.  active=0;
  95. }
  96.  
  97. void LetterListWindow :: Save(void)
  98. {
  99.  char filename[255];
  100.  FILE *fd;
  101.  WINDOW *question;
  102.  int i;
  103.  
  104.  init_pair(43, COLOR_WHITE, COLOR_RED);
  105.  init_pair(44, COLOR_YELLOW, COLOR_RED);
  106.  question = newwin(5, 60, 10, 10);
  107.  wattrset(question, COLOR_PAIR(43) | A_BOLD);
  108.  for(i=0; i<5*60; i++)
  109.         waddch(question, ' ');
  110.  wborder(question, 0, 0, 0, 0, 0, 0, 0, 0);
  111.  mvwaddstr(question, 1, 2, "Save to file:");
  112.  mvwaddch(question, 2, 2, '<');
  113.  mvwaddch(question, 2, 57, '>');
  114.  mvwaddstr(question, 3, 30, "Ctrl-C + any key = Cancel");
  115.  sprintf(filename, "%s%s", mm.resourceObject->get(bwSaveDir), mm.areaList->getName());
  116.  if(getstring(question, 2, 3, filename, 54, COLOR_PAIR(43) | A_BOLD,
  117.                    COLOR_PAIR(44) | A_BOLD))
  118.         if((fd=fopen(filename, "w")) != NULL)
  119.         {
  120.           for(i=1; i <= mm.areaList->getNoOfLetters(); i++)
  121.                  {
  122.                    letterList->gotoLetter(i);
  123.                 letterwindow.write_to_file(fd);
  124.                    }
  125.          fclose(fd);
  126.         }
  127.  delwin(question);
  128.  touchwin(screen);
  129.  wnoutrefresh(screen);
  130.  touchwin(list);
  131.  Draw();
  132.  helpwindow.redraw();
  133. }
  134.  
  135. void LetterListWindow::FirstUnread(void)
  136. {
  137.  int i;
  138.  
  139.  position=0;
  140.  active=0;
  141.  for(i=0; i<NumOfItems(); i++)
  142.  {
  143.     letterList->gotoLetter(i+1);    
  144.     if(letterList->getRead()) 
  145.     {
  146.         Move(DOWN);
  147.         Draw();
  148.         doupdate();
  149.     }
  150.     else 
  151.         i=NumOfItems();
  152.  }
  153.  Draw();
  154. }
  155.  
  156. int LetterListWindow::NumOfItems(void)
  157. {
  158.  return mm.areaList->getNoOfLetters(); 
  159. }
  160.  
  161. void LetterListWindow::Draw(void)
  162. {
  163.  int i;
  164.  char *tmp;
  165.  
  166.  init_pair(26, COLOR_WHITE, COLOR_BLUE);
  167.  tmp = new char[COLS-47];
  168.  tmp[COLS-48]='\0';
  169.  for(i=1; i<list_max_y; i++)
  170.  {
  171.   int x,y;
  172.   
  173.   letterList->gotoLetter(position+i);
  174.   wattrset(list, COLOR_PAIR(26) | A_NORMAL);
  175.   if(!letterList->getRead()) wattron(list, A_BOLD);
  176.   if(position+i-1 == active) wattron(list, A_REVERSE);
  177.   mvwprintw(list, i+1, 1, " %5d", letterList->getLetterID());
  178.   mvwprintw(list, i+1, 7, "  %-16s", letterList->getFrom());
  179.   mvwprintw(list, i+1, 23, " %-16s", letterList->getTo());
  180.   strncpy(tmp, letterList->getSubject(), COLS-58);
  181.   mvwprintw(list, i+1, 38, " %s", tmp);
  182.   getyx(list, y, x);
  183.   if(mm.areaList->getType() == bwrep)
  184.   {
  185.     while(x < COLS-20)
  186.       mvwaddch(list, y, x++, ' ');
  187.       mvwprintw(list, i+1, COLS-20, " %-14s", mm.areaList->getName(letterList->getAreaID()));
  188.   }  
  189.   else
  190.   {
  191.     while(x < COLS-5)
  192.       mvwaddch(list, y, x++, ' ');
  193.   }
  194.   if((position+i) == NumOfItems()) i=list_max_y;
  195.  } 
  196.  delete tmp;
  197.  wnoutrefresh(list);
  198. }
  199.  
  200. void LetterListWindow::MakeActive(void)
  201. {
  202.  int i;
  203.  
  204.  areas.Reset_areaList();
  205.  if(NumOfItems() < LINES-11)
  206.     list_max_y = NumOfItems() + 1;
  207.  else list_max_y = LINES - 10;
  208.  list=newwin(list_max_y + 2, COLS - 4, 2, 2);
  209.  init_pair(21, COLOR_YELLOW, COLOR_BLUE);
  210.  init_pair(22, COLOR_WHITE, COLOR_BLUE);
  211.  init_pair(23, COLOR_GREEN, COLOR_BLUE);
  212.  init_pair(25, COLOR_YELLOW, COLOR_BLUE);
  213.  wattrset(list, COLOR_PAIR(21) | A_BOLD);
  214.  
  215.  for(i=0; i<(LINES-8)*(COLS-4); i++)
  216.     waddch(list, ' '); 
  217.  wborder(list, 0, 0, 0, 0, 0, 0, 0, 0);
  218.  mvwaddch(list, 0, 2, ACS_RTEE);
  219.  wattrset(list, COLOR_PAIR(22) | A_BOLD);
  220.  waddstr(list, "Letters in ");
  221.  wattrset(list, COLOR_PAIR(23) | A_BOLD);
  222.  wprintw(list, "%s", mm.areaList->getDescription());
  223.  wattrset(list, COLOR_PAIR(21) | A_BOLD);
  224.  waddch(list, ACS_LTEE); 
  225.  wattrset(list, COLOR_PAIR(25) | A_BOLD);
  226.  mvwaddstr(list, 1, 3, "MSG#  From           To             Subject"); 
  227.  if(mm.areaList->getType() == bwrep)
  228.     mvwaddstr(list, 1, COLS-19, "Area"); 
  229.  wnoutrefresh(list);
  230.  
  231.  helpwindow.letterlist();
  232. }
  233.  
  234. void LetterListWindow::Delete(void)
  235. {
  236.  letterList->gotoLetter(active+1);
  237.  delwin(list);
  238.  helpwindow.Delete();
  239.  touchwin(screen);
  240.  wnoutrefresh(screen);
  241. }
  242.  
  243. //****************************************************************************
  244. //*                                                                          *
  245. //*                          LETTERWINDOW                              *
  246. //*                                                                          *
  247. //****************************************************************************
  248.  
  249. Line :: Line(void)
  250. {
  251.     next = NULL;
  252. }
  253.  
  254. net_address LetterWindow :: PickNetAddr(void)
  255. {
  256.  unsigned int i;
  257.  Line *line;
  258.  net_address result; 
  259.  
  260.  line = head.next;
  261.  while(strncmp(" * Origin:", line->text, 10) != 0)
  262.     line = line->next;
  263.  //we have the Origin line
  264.  
  265.  i = strlen(line->text);
  266.  while(((line->text[i-1]) != '(') && i > 0)
  267.      i--;
  268.  //we have the opening bracket
  269.  
  270.  while((i < strlen(line->text)) && ((line->text[i]<'0') || (line->text[i]>'9')))
  271.     i++;
  272.  //we have the begining of the address
  273.  
  274.  if(sscanf(&line->text[i], "%d:%d/%d.%d", &result.zone,
  275.                       &result.net,
  276.                       &result.node,
  277.                       &result.point) == 3)
  278.     result.point = 0;
  279.  
  280.  return result;
  281. }
  282.  
  283. void LetterWindow :: set_columns(int arg)
  284. {
  285.     columns = arg;
  286. }
  287.  
  288. void LetterWindow :: ReDraw(void)
  289. {
  290.     touchwin(header);
  291.     wnoutrefresh(header);
  292.     touchwin(text);
  293.     wnoutrefresh(text);
  294. }
  295.  
  296. void LetterWindow :: DestroyChain (void)
  297. {
  298.  Line *tmp;
  299.  
  300.  curr = head.next;
  301.  while(curr != NULL)
  302.  {
  303.     delete curr->text;
  304.     tmp = curr;
  305.     curr = curr->next;
  306.     delete tmp;
  307.  }
  308.  head.next = NULL;
  309.  letter_in_chain = 0;
  310.  NumOfLines = 0;
  311. }
  312.  
  313. void LetterWindow :: MakeChain (void)
  314. {
  315.  char *message;
  316.  int end = 0;
  317.  int j = 0; //pointer in the text
  318.  int k;     //pointer in the line 
  319.  int begin; //pointer to the begining of the last word
  320.  
  321.  DestroyChain();
  322.  message = (char *)letterList->getBody(); 
  323.  letter_in_chain = letterList->getLetterID();
  324.  curr = &head;
  325.  
  326.  while(!end)
  327.  {
  328.   //new line
  329.   curr->next = new Line;
  330.   curr = curr->next;
  331.   curr->text = new char[columns + 1]; //+1 for the '\0'
  332.   NumOfLines++;
  333.  
  334.   begin = 0;
  335.   k = 0;
  336.   while((message[j] != 13) && (message[j] != 10) && (!end) && (k < columns))
  337.   {
  338.     if((begin == 0) && (message[j] != ' '))
  339.         begin = j;
  340.     if(message[j] == ' ')
  341.         begin = 0;
  342.     if(message[j] != '\0')
  343.     {
  344.         //put character to its place
  345.         curr->text[k] = message[j];
  346.         j++;
  347.         k++;
  348.     }
  349.     else 
  350.         end = 1;
  351.   }
  352.   if(k == columns && begin != 0 && (j-begin) < columns)
  353.   {
  354.     //we must go back to 'begin'
  355.     k-= j - begin;
  356.     j = begin;
  357.     
  358.   }
  359.   if((message[j] == 10) || (message[j] == 13)) j++;//to omit the '\n'
  360.   if((message[j-1] == 13) && (message[j] == 10)) j++;
  361.   curr->text[k] = '\0';
  362.  }
  363. }
  364.  
  365. void LetterWindow :: Draw()
  366. {
  367.  unsigned int i, j;
  368.  char    test;
  369.  
  370.  if(letter_in_chain != letterList->getLetterID()) 
  371.     MakeChain();
  372.  letterList->setRead();
  373.  touchwin(text);
  374.  init_pair(32, COLOR_BLUE, COLOR_BLACK);
  375.  init_pair(33, COLOR_CYAN, COLOR_BLACK);
  376.  init_pair(34, COLOR_YELLOW, COLOR_RED);
  377.  init_pair(35, COLOR_RED, COLOR_BLACK);
  378.  init_pair(36, COLOR_GREEN, COLOR_BLACK);
  379.  init_pair(37, COLOR_MAGENTA, COLOR_BLACK);
  380.  init_pair(38, COLOR_WHITE, COLOR_BLACK);
  381.  wattrset(header, COLOR_PAIR(32) | A_BOLD);
  382.  wmove(header, 0, 0);
  383.  for(i=0; i<(unsigned int)(4*(columns-2)); i++)
  384.     waddch(header, ' ');
  385.  mvwaddstr(header, 0,  2, "MSG#:");
  386.  mvwaddstr(header, 1,  2, "From:");
  387.  mvwaddstr(header, 2,  2, "  To:");
  388.  mvwaddstr(header, 3,  2, "Subj:");
  389.  mvwaddstr(header, 0, COLS-33, "Date:"); 
  390.  wattrset(header, COLOR_PAIR(35));
  391.  mvwprintw(header, 0,  8, "%d of %d", letterList->getLetterID(),
  392.        mm.areaList->getNoOfLetters());
  393.  mvwprintw(header, 3, COLS-15, "%5d%c%-5d", position + 1, '/', NumOfLines - 1);
  394.  wattrset(header, COLOR_PAIR(36));
  395.  mvwaddstr(header, 1,  8, (char *)letterList->getFrom());
  396.  wattrset(header, COLOR_PAIR(33));
  397.  mvwaddstr(header, 2,  8, (char *)letterList->getTo());
  398.  wattrset(header, COLOR_PAIR(36) | A_BOLD);
  399.  mvwaddstr(header, 3,  8, (char *)letterList->getSubject()); 
  400.  mvwaddstr(header, 0, COLS-27, (char *)letterList->getDate());
  401.  
  402.  wnoutrefresh(header);
  403.  
  404.  //find positionth Line
  405.  curr = head.next;
  406.  for(i = 0; i < position; i++)
  407.     curr = curr->next;
  408.  for(i = 1; i <= (unsigned int)y; i++)
  409.      if(curr != NULL) 
  410.     {
  411.         wattrset(text, COLOR_PAIR(36));
  412.         for(int m=0; m<5; m++)
  413.             if(curr->text[m] == '>')  //quoting
  414.                 wattrset(text, COLOR_PAIR(33));
  415.         test = curr->text[0];
  416.         if((curr->text[1] == test) && (curr->text[2] == test) &&
  417.           ((curr->text[3] == ' ') || (curr->text[3] == '\r')))
  418.             switch(test)
  419.             {
  420.                 case '.': wattrset(text, COLOR_PAIR(37) |
  421.                            A_BOLD); //tagline
  422.                       break;
  423.                 case '-': wattrset(text, COLOR_PAIR(35));
  424.                             //mailer prog
  425.                       break;
  426.                 case '~': wattrset(text, COLOR_PAIR(35));
  427.                             //mailer prog
  428.                       break;
  429.             }
  430.         else if((strncmp(curr->text, " * Origin:", 10)) == 0)
  431.             wattrset(text, COLOR_PAIR(38) | A_BOLD); //origin line
  432.          
  433.         mvwprintw(text, i, 0, "%-80s", curr->text);        
  434.         curr = curr->next;
  435.     }
  436.     else
  437.         for(j = 0; j < (unsigned int)x; j++)
  438.             mvwaddch(text, i, j, ' ');
  439.  wattrset(text, COLOR_PAIR(34) | A_BOLD);
  440.  mvwprintw(text, LINES-6, 0, " %-71s",
  441.  mm.areaList->getDescription());
  442.  for(i=0; i<(unsigned int)(columns-79); i++) waddch(text, ' ');
  443.  waddstr(text, "F1-Help");
  444.  
  445.  wnoutrefresh(text);
  446. }
  447.  
  448. void LetterWindow :: MakeActive(void)
  449. {
  450.  int i;
  451.  
  452.  init_pair(31, COLOR_BLUE, COLOR_BLACK);
  453.  
  454.  DestroyChain();
  455.  header=newwin(4, COLS-2, 1, 1);
  456.  text=newwin(LINES-5, COLS, 5, 0);
  457.  wattrset(text, COLOR_PAIR(31) | A_BOLD);
  458.  for(i=0; i<((LINES-5)*(COLS)); i++)
  459.     waddch(text, ' ');
  460.  mvwaddch(text, 0, 0, ACS_LLCORNER);
  461.  whline(text, ACS_HLINE, COLS-2);
  462.  mvwaddch(text, 0, COLS-1, ACS_LRCORNER);
  463.  
  464.  getmaxyx(text, y, x);   
  465.  y-=2; //the border and the status line
  466.  position = 0;
  467.  Draw();
  468. }
  469.  
  470. void LetterWindow :: Next(void)
  471. {
  472.  if(letterList->getLetterID() < mm.areaList->getNoOfLetters())
  473.     {
  474.      letters.Move(DOWN);
  475.      letterList->gotoLetter(letterList->getLetterID() + 1);
  476.      position=0;
  477.      Draw();
  478.     }
  479.  else
  480.  {
  481.   interface->back();
  482.   doupdate();
  483.   interface->back();
  484.   doupdate();
  485.   interface->DOWN_ARROW();
  486.  }
  487. }
  488.  
  489. void LetterWindow :: Previous(void)
  490. {
  491.  if(letterList->getLetterID() > 1)
  492.     {
  493.      letters.Move(UP);
  494.      letterList->gotoLetter(letterList->getLetterID() - 1);
  495.      position=0;
  496.      Draw();
  497.     }
  498.  else
  499.  {
  500.   interface->back();
  501.   doupdate();
  502.   interface->back();
  503.   doupdate();
  504.   interface->UP_ARROW();
  505.  }
  506. }
  507.  
  508. void LetterWindow :: Move(direction dir)
  509. {
  510.  switch(dir)
  511.  {
  512.     case UP: if(position > 0)
  513.             {
  514.              position--; 
  515.                  Draw(); 
  516.             }
  517.          break;
  518.     case DOWN: if(position < NumOfLines - 2) 
  519.            {
  520.              position++; 
  521.              Draw();
  522.            }
  523.            break;
  524.     case HOME: position = 0; Draw(); break;
  525.     case END: position = NumOfLines - 2;
  526.           Draw();
  527.           break;
  528.     case PGUP: if((unsigned int)y < position)
  529.             position-=y;
  530.            else
  531.             position = 0;
  532.            Draw();
  533.            break;
  534.     case PGDN: position+=y;
  535.            if(position > NumOfLines - 2)
  536.             position = NumOfLines - 2;
  537.            Draw();
  538.            break;
  539.  }
  540. }
  541.  
  542. void LetterWindow :: Delete(void)
  543. {
  544.  if(header != NULL) delwin(header);
  545.  if(text != NULL) delwin(text);
  546.  touchwin(screen);
  547.  wnoutrefresh(screen);
  548. }
  549.  
  550. void LetterWindow :: Save(void)
  551. {
  552.  char filename[255];
  553.  WINDOW *question;
  554.  FILE *fd;
  555.  
  556.  init_pair(43, COLOR_WHITE, COLOR_RED);
  557.  init_pair(44, COLOR_YELLOW, COLOR_RED);
  558.  question = newwin(5, 60, 10, 10);
  559.  wattrset(question, COLOR_PAIR(43) | A_BOLD);
  560.  for(int i=0; i<5*60; i++)
  561.     waddch(question, ' ');
  562.  wborder(question, 0, 0, 0, 0, 0, 0, 0, 0);
  563.  mvwaddstr(question, 1, 2, "Save to file:");
  564.  mvwaddch(question, 2, 2, '<');
  565.  mvwaddch(question, 2, 57, '>');
  566.  mvwaddstr(question, 3, 30, "Ctrl-C + any key = Cancel");
  567.  sprintf(filename, "%s%s%c%d", mm.resourceObject->get(bwSaveDir), 
  568.     mm.areaList->getName(), '.', letterList->getLetterID());
  569.  if(getstring(question, 2, 3, filename, 54, COLOR_PAIR(43) | A_BOLD, 
  570.                COLOR_PAIR(44) | A_BOLD))
  571.      if((fd=fopen(filename, "w")) == NULL)
  572.         {
  573.          #ifdef SOUND_EFFECTS
  574.           system("zcat /var/lib/mmail/ohno.wav >/dev/dsp &");
  575.          #endif
  576.         }
  577.     else 
  578.         {
  579.          write_to_file(fd);
  580.          fclose(fd);
  581.         }
  582.  delwin(question);
  583.  Draw();
  584. }
  585.  
  586. void LetterWindow :: set_Letter_Params(net_address *nm, char to[30])
  587. {
  588.  NM.zone  = nm->zone;
  589.  NM.net   = nm->net;
  590.  NM.node  = nm->node;
  591.  NM.point = nm->point;
  592.  if(to != NULL)
  593.     strncpy(To, to, 29);
  594.  else
  595.     To[0] = '\0';
  596. }
  597.  
  598. void LetterWindow :: set_Letter_Params(int area, char param_key)
  599. {
  600.  key = param_key;
  601.  if(key == 'N')
  602.  { 
  603.      //find netmail area
  604.     int i=1;
  605.     while((i <= mm.areaList->noOfAreas()) && 
  606.           (strcmp(mm.areaList->getShortName(), "NET") != 0))
  607.         mm.areaList->gotoArea(i++);
  608.     if(strcmp(mm.areaList->getShortName(), "NET") == 0)
  609.         replyto_area = mm.areaList->getAreaNo();
  610.     else
  611.     {
  612.     //netmail area not found, we should warn the user
  613.     } 
  614.     areas.Reset_areaList();
  615.  }
  616.  else
  617.     replyto_area = area; 
  618. }
  619.  
  620. void LetterWindow :: EnterLetter(void)
  621. {
  622.  WINDOW *rep_header;
  623.  char tmp_filename[255];
  624.  FILE *tmp;
  625.  char reply_filename[255];
  626.  char command[255];
  627.  char FROM[21];
  628.  char TO[21];
  629.  char SUBJ[72];
  630.  char TMP[21];
  631.  char mg[4];
  632.  FILE *reply; 
  633.  int end, i;
  634.  TaglineWindow *taglines;
  635.  
  636.  init_pair(53, COLOR_WHITE, COLOR_BLUE);
  637.  init_pair(54, COLOR_CYAN, COLOR_BLUE);
  638.  init_pair(55, COLOR_GREEN, COLOR_BLUE);
  639.  
  640.  rep_header = newwin(5, COLS-2, (LINES/2)-3, 1);
  641.  wattrset(rep_header, COLOR_PAIR(53) | A_BOLD);
  642.  for(i=0; i<5*(COLS-2); i++)
  643.     waddch(rep_header, ' ');
  644.  box(rep_header, 0, 0);
  645.  mvwaddstr(rep_header, 1, 2, "From:");
  646.  mvwaddstr(rep_header, 2, 2, "  To:");
  647.  mvwaddstr(rep_header, 3, 2, "Subj:"); 
  648.  wrefresh(rep_header);
  649.  
  650.  mm.areaList->gotoArea(replyto_area);
  651.  strcpy(FROM, mm.resourceObject->get(bwAliasName));
  652.  if(strcmp(mm.areaList->getShortName(), "NET") != 0)
  653.      getstring(rep_header, 1, 8, FROM, 20, COLOR_PAIR(55), COLOR_PAIR(55));
  654.  else
  655.     mvwaddstr(rep_header, 1, 8, FROM); 
  656.  if((key == 'R') || (key == 'N'))
  657.        strcpy(TO, letterList->getFrom());
  658.  
  659.  if(key == 'O')
  660.        strcpy(TO, letterList->getTo());
  661.  
  662.  if(key == 'E')
  663.  {
  664.   if(To[0] == '\0')
  665.       strcpy(TO, "ALL");
  666.   else
  667.     strcpy(TO, To);
  668.   SUBJ[0]='\0'; //we don't have subject yet
  669.  }
  670.  else
  671.   strcpy(SUBJ, letterList->getSubject());
  672.  
  673.  
  674.  if(strcmp(mm.areaList->getShortName(), "NET") != 0) 
  675.     getstring(rep_header, 2, 8, TO, 20, COLOR_PAIR(54), COLOR_PAIR(54)); 
  676.  else     if(NM.point)
  677.         mvwprintw(rep_header, 2, 8, "%s (%d:%d/%d.%d)",    TO,
  678.                                 NM.zone,
  679.                                 NM.net,
  680.                                 NM.node,
  681.                                 NM.point);
  682.     else
  683.         mvwprintw(rep_header, 2, 8, "%s (%d:%d/%d)",      TO,
  684.                                 NM.zone,
  685.                                 NM.net,
  686.                                 NM.node);
  687.  getstring(rep_header, 3, 8, SUBJ, 69, COLOR_PAIR(55) | A_BOLD,
  688.         COLOR_PAIR(55) | A_BOLD);
  689.  delwin(rep_header);
  690.   
  691.  sprintf(reply_filename, "%s%s%s", "/tmp/", getenv("LOGNAME"), "/reply.txt"); 
  692.  reply=fopen(reply_filename, "w");
  693.  if(key == 'E')
  694.      fclose(reply);      //this was only delete the file
  695.  else
  696.  {
  697.   fprintf(reply, "\n   -=> %s wrote to %s <=-\n\n", letterList->getFrom(),
  698.      letterList->getTo());
  699.   fclose(reply); 
  700.   sprintf(tmp_filename, "%s%s%s", "/tmp/", getenv("LOGNAME"), "/tmp.txt");
  701.   if((tmp=fopen(tmp_filename, "w")) != NULL) 
  702.   {
  703.     columns = 75;
  704.     write_to_file(tmp, 0);
  705.     columns = COLS;
  706.     fclose(tmp);
  707.     MakeChain();
  708.   }
  709.   strncpy(mg, letterList->getFrom(), 2);
  710.   mg[2]='\0'; mg[3]='\0';
  711.   strcpy(TMP, letterList->getFrom());
  712.   i=1;
  713.   for(int j=1; j<3; j++)
  714.   {
  715.      end=0;
  716.       while((TMP[i] != '\0') && !end)
  717.      {
  718.          if((TMP[i-1] == ' ') && (TMP[i] != ' '))
  719.              {
  720.               mg[j]=TMP[i];
  721.              if(j==1) end=1;
  722.          }
  723.          i++;
  724.      }
  725.   }
  726.   sprintf(command, "%s%s%s%s%s%s", "sed 's/^/ ", mg, "> /' ", tmp_filename,
  727.      " >> ", reply_filename); 
  728.   system(command);
  729.  }
  730.  sprintf(command, "%s %s", mm.resourceObject->get(editor), reply_filename);
  731.  leaveok(stdscr, FALSE);
  732.  refresh();
  733.  system(command);
  734.  keypad(screen, TRUE); 
  735.  leaveok(stdscr, TRUE);
  736.  touchwin(stdscr);
  737.  refresh();
  738.  touchwin(screen);
  739.  wnoutrefresh(screen);
  740.  switch(interface->active())
  741.  {
  742.     case packetlist: break;
  743.     case arealist: areas.ReDraw(); break;
  744.     case letterlist: letters.ReDraw(); break;
  745.     case threadlist: break;
  746.     case letter: letterwindow.ReDraw(); break;
  747.     case letter_help: break;
  748.     case littlearealist: break;
  749.  }
  750.  
  751.  /* place tagline after the text */
  752.  
  753.  tagline[0] = '\0';
  754.  taglines = new TaglineWindow;
  755.  if(tagline[0] != '\0')
  756.  {
  757.      reply=fopen(reply_filename, "a+");
  758.      fseek(reply, -1, SEEK_CUR);
  759.      if(fgetc(reply) != '\n')
  760.         fputc('\n', reply);
  761.     fprintf(reply, "... %s\n", tagline);
  762.     fclose(reply);
  763.  }
  764.  
  765.  if(strcmp(mm.areaList->getShortName(), "NET") == 0)
  766.  {
  767.     mm.areaList->enterLetter(replyto_area, FROM, TO, SUBJ, 0, 0, &NM);
  768.  }
  769.  else
  770.     mm.areaList->enterLetter(replyto_area, FROM, TO, SUBJ, 0, 0, NULL);
  771.  areas.Reset_areaList();
  772.  To[0] = '\0';
  773. }
  774.  
  775. void LetterWindow :: set_Tagline(char *tl)
  776. {
  777.  strncpy(tagline, tl, 76);
  778. }
  779.  
  780. void LetterWindow :: write_to_file(FILE *fd, int NEED_HEADER)
  781. {
  782.  int j;
  783.  
  784.  if(NEED_HEADER)
  785.  { //write header to file
  786.   fputc('\n', fd);
  787.   for(j=0; j<COLS; j++)
  788.     fputc('=', fd);
  789.   fprintf(fd, "\n   From: %s\n     To: %s\n   Subj: %s\n", 
  790.          letterList->getFrom(), letterList->getTo(), letterList->getSubject()); 
  791.   for(j=0; j<COLS; j++)
  792.         fputc('-', fd);
  793.   fputc('\n', fd);
  794.  }
  795.  //write chain to file
  796.  MakeChain();
  797.  curr = head.next;
  798.  while(curr != NULL)
  799.  {
  800.     fprintf(fd, "%s\n", curr->text);
  801.     curr = curr->next;
  802.  }
  803. }
  804.